package main

import (
	"encoding/json"
	"fmt"
	"os"
)

type Response1 struct {
	Page   int
	Fruits []string
}

type Response2 struct {
	Page   int      `json:"page"`
	Fruits []string `json:"fruits"`
}

var p = fmt.Println

func main() {

	bolB, _ := json.Marshal(true)
	p(string(bolB))
	intB, _ := json.Marshal(1)
	p(string(intB))
	fltB, _ := json.Marshal(2.34)
	p(string(fltB))
	strB, _ := json.Marshal("gopher")
	p(string(strB))

	slcD := []string{"apple", "peach", "pear"}
	slcB, _ := json.Marshal(slcD)
	fmt.Println(string(slcB))

	mapD := map[string]int{
		"alan":      1,
		"ghost-him": 2,
		"NOC":       3,
	}
	mapB, _ := json.Marshal(mapD)
	p(string(mapB))

	// struct data
	res1 := Response1{5, []string{"apple", "banana"}}
	res1B, _ := json.Marshal(res1)
	p(string(res1B))

	res2 := Response2{6, []string{"peach", "pear"}}
	res2B, _ := json.Marshal(res2)
	p(string(res2B))

	// decode into Go values
	byt := []byte(`{"num":3.14,"str":"hahaha"}`)

	var data map[string]interface{}

	if err := json.Unmarshal(byt,&data);err != nil{
		p(err)
	}
	p("num:",data["num"].(float64))
	p("str:",data["str"].(string))


	enc := json.NewEncoder(os.Stdout)
    d := map[string]int{"apple": 5, "lettuce": 7}
    enc.Encode(d)



}
